<template>
  <div class="app-container">
    <div class="filter-container">
      <el-button class="filter-item" type="primary" v-waves icon="el-icon-plus" @click="handleUpdate(null)">添加</el-button>


      <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="品牌名称" v-model="filters.like$title"></el-input>



      <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
      <el-button class="filter-item" type="primary" v-waves icon="el-icon-document" @click="exportExcelFile">导出</el-button>
    </div>
    <el-table :data="list" @sort-change="sortChange" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row
      style="width: 100%">
      <el-table-column align="center" type="index" label="序号" width="80">
      </el-table-column>



      <el-table-column prop="logo" align="center" label="名牌Logo" width="220">
        <template slot-scope="scope">
          <img :src="scope.row.logo|absUrl" alt="" class="avatar">
        </template>
      </el-table-column>


      <el-table-column prop="title" align="center" label="品牌名称" width="220">
        <template slot-scope="scope">
          <span>{{scope.row.title}}</span>
        </template>
      </el-table-column>


      <el-table-column prop="urlAlias" align="center" label="URL重写" width="220">
        <template slot-scope="scope">
          <span>{{scope.row.urlAlias}}</span>
        </template>
      </el-table-column>


      <el-table-column prop="sort" align="center" label="显示顺序" width="120">
        <template slot-scope="scope">
          <span>{{scope.row.sort}}</span>
        </template>
      </el-table-column>





      <el-table-column align="center" label="操作" width="200" class-name="small-padding">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">修改</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="params.page"
        :page-sizes="[10,20,30,50]" :page-size="params.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>

    <el-dialog :title="isEditing?'修改':'添加'" :visible.sync="dialogFormVisible">
      <el-form class="dialog-form" :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="120px">



        <el-form-item label="品牌名称" prop="title">


          <el-input v-model="temp.title" placeholder="品牌名称不能超过20个字符"></el-input>


        </el-form-item>

        <el-form-item label="URL重写" prop="urlAlias">


          <el-input v-model="temp.urlAlias" placeholder="URL重写"></el-input>


        </el-form-item>

        <el-form-item label="显示顺序" prop="sort">

          <el-row>
            <el-col :span="12">
              <el-input v-model="temp.sort" type="number" placeholder="显示顺序"></el-input>
            </el-col>
          </el-row>



        </el-form-item>
        <el-form-item label="名牌Logo" prop="logo">
          <el-upload class="avatar-uploader" :action="UPLOAD_URL" :show-file-list="false" :on-success="handleAvatarSuccess('logo')"
            :before-upload="beforeAvatarUpload">
            <img v-if="temp.logo" :src="temp.logo|absUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>

        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" :loading="submiting" @click="submitFormAction">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        temp: {

          id: '',

          logo: '',

          title: '',

          urlAlias: '',

          sort: 0,

        },

        rules: {

          logo: [{
            required: true,
            message: "名牌Logo不能为空",
            trigger: "change"
          }],

          title: [{
              required: true,
              message: "品牌名称不能为空",
              trigger: "change"
            },
            {
              max: 20,
              message: "品牌名称不能超过20个字符",
              trigger: "change"
            }
          ],
          sort: [{
            required: true,
            message: "显示顺序不能为空",
            trigger: "change"
          }],

        }
      };
    },
    created() {
      this.init("goods_brand", 1).loadData();
    },
    filters: {

    },
    methods: {
      exportExcelFile() {
        this.exportExcel({
          title: "商品品牌",
          fields: [
            // {field:'logo',title:'名牌Logo'}
            // ,
            {
              field: 'title',
              title: '品牌名称'
            },
            {
              field: 'urlAlias',
              title: 'URL重写'
            },
            {
              field: 'sort',
              title: '显示顺序'
            }
          ]
        }).then(info => {
          this.openWin(info);
        });
      }
    }
  };

</script>
<style scoped>
  .avatar {
    width: 100px;
    display: block;
    margin: 0 auto;
    height: 100px;
  }

</style>
